package ExerciseThree;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import org.junit.Test;
/**
 * 对图片的加密
 * @author 石文学
 *
 */
public class SecretTest {
	@Test
	public void test1()
	{
		FileInputStream fis=null;
		FileOutputStream fos=null;
		try {
			File file1 = new File("微信图片_20220625223251.jpg");
			File file2 = new File("D:\\JavaProject\\Exercise2\\src\\微信图片_2022062522325102.jpg");
			fis = new FileInputStream(file1);
			fos = new FileOutputStream(file2);
			byte buffer[] = new byte[20];
			int len;
			while((len = fis.read(buffer))!=-1)
			{
				for(int i=0;i<len;i++)
				{
					buffer[i] = (byte)(buffer[i]^5);
				}
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally
		{
			if(fis!=null)
			{
				try {
					fis.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			if(fos!=null)
			{
				try {
					fos.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}

	@Test
	public void test2()
	{
		FileInputStream fis=null;
		FileOutputStream fos=null;
		try {
			File file1 = new File("D:\\JavaProject\\Exercise2\\src\\微信图片_2022062522325102.jpg");
			File file2 = new File("微信图片_2022062522325103.jpg");
			fis = new FileInputStream(file1);
			fos = new FileOutputStream(file2);
			byte buffer[] = new byte[20];
			int len;
			while((len = fis.read(buffer))!=-1)
			{
				for(int i=0;i<len;i++)
				{
					buffer[i] = (byte)(buffer[i]^5);
				}
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally
		{
			if(fis!=null)
			{
				try {
					fis.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			if(fos!=null)
			{
				try {
					fos.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}
}
